package com.web.exiaodao.remote.vo;

import com.google.common.base.Function;
import com.web.webstart.base.util.CollectionUtils;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by dazer on 2017/3/12.
 * 加盟协议
 */
@ApiModel(value = "加盟协议Vo对象")
public class FranchiseAgreementVo {
    @ApiModelProperty(value = "主键，自动增长")
    private Long id;
    @ApiModelProperty(value = "协议名称")
    private String name;
    @ApiModelProperty(value = "协议访问路径,相对路径")
    private String path;

    public FranchiseAgreementVo() {
    }

    /**
     * 获取所有的协议
     *
     * @return
     */
    public static List<FranchiseAgreementVo> getAllAgreements() {
        List<FranchiseAgreementVo> list = new ArrayList<>();
        list.add(new FranchiseAgreementVo(1l, "尊老达人合作协议", "/upload/protocolDocs/docs1.doc"));
        list.add(new FranchiseAgreementVo(2l, "尊老合作协议", "/upload/protocolDocs/docs2.doc"));
        list.add(new FranchiseAgreementVo(3l, "尊老机构合作协议", "/upload/protocolDocs/docs3.docx"));
        list.add(new FranchiseAgreementVo(4l, "Business Agreement", "/upload/protocolDocs/docs4.docx"));
        return list;
    }

    public static String getFranchiseAgreementNameById(Long id) {
        Map<Long, FranchiseAgreementVo> map = CollectionUtils.listToMap(getAllAgreements().iterator(), new Function<FranchiseAgreementVo, Long>() {
            @Override
            public Long apply(FranchiseAgreementVo franchiseAgreementVo) {
                return franchiseAgreementVo.getId();
            }
        });
        FranchiseAgreementVo vo =  map.get(id);
        return vo != null ? vo.getName() : "";
    }

    /**
     * 判断选择的协议是否存在
     *
     * @param keys
     * @return
     * @throws Exception
     */
    public static boolean isContainKey(List<Long> keys) throws Exception {
        List<Long> list = CollectionUtils.subCollection(getAllAgreements(), "id");
        return list.containsAll(keys);
    }

    public FranchiseAgreementVo(Long id, String name, String path) {
        this.id = id;
        this.name = name;
        this.path = path;
    }


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
